/////////////////////////////////////////////////////////////////////////////
// Name:        ax_menu_alert.cpp
// Purpose:     Modal alert menu class, an equivalent of wxMessageBox.
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#include "wx/wx.h"

#include "ax/ax_menu_alert.h"

IMPLEMENT_CLASS( AxModalAlertMenu, AxModalMenu )

AxModalAlertMenu::AxModalAlertMenu(AxMenuController* controller, AxMenuItem* item,
        const wxString& menuLabel,
        const wxString& description,
        const wxString& mainItemLabel,
        int style,
        const wxString& okItemLabel,
        const wxString& cancelItemLabel,
        const wxString& yesItemLabel,
        const wxString& noItemLabel,
        const wxString defaultId):
    AxModalMenu(controller, item)
{
    Init();

    AxMenu* menu = new AxMenu;
    menu->SetLabel(menuLabel);
    menu->SetDescription(description);

    wxArrayString labels, ids, descriptions;

    labels.Add(mainItemLabel);
    ids.Add(AxIdentifierMainItem);
    descriptions.Add(description);

    if (style & axALERT_YES_NO)
    {
        labels.Add(yesItemLabel);
        ids.Add(AxIdentifierYes);
        descriptions.Add(_("Yes")); // ??

        labels.Add(noItemLabel);
        ids.Add(AxIdentifierNo);
        descriptions.Add(_("No")); // ??
    }

    if (style & axALERT_OK)
    {
        labels.Add(okItemLabel);
        ids.Add(AxIdentifierOK);
        descriptions.Add(_("Confirm this operation."));
    }

    if (style & axALERT_CANCEL)
    {
        labels.Add(cancelItemLabel);
        ids.Add(AxIdentifierCancel);
        descriptions.Add(_("Cancel this operation."));
    }

    size_t i;
    for (i = 0; i < labels.GetCount(); i++)
    {
        wxString label = labels[i];
        wxString id = ids[i];
        wxString descr = descriptions[i];

        AxMenuItem* child = new AxMenuItem(label, descr, id,
            new AxAlertMenuActivator(this));
        child->GetActivator()->SetMenuItem(child);
        child->SetStyle(AxMenuStyleBold);
        menu->AddItem(child);

        if (defaultId == id)
            menu->SetCurrentSelection(i);
    }

    SetMenu(menu);
}

/*
 * AxAlertMenuActivator implementation.
 * Ends the modal menu when the item is activated.
 */

IMPLEMENT_DYNAMIC_CLASS( AxAlertMenuActivator, AxActivator )

void AxAlertMenuActivator::Copy(const AxAlertMenuActivator& activator)
{
    AxActivator::Copy(activator);
    m_alertMenu = activator.m_alertMenu;
}

AxMenu* AxAlertMenuActivator::Activate(AxMenuController* WXUNUSED(controller), AxMenuItem* item)
{
    if (m_alertMenu)
        m_alertMenu->EndModal(item->GetId());
    return NULL;
}
